package com.example.qu_tao.View;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.qu_tao.R;

public class shezhiActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView settingBack;
    private LinearLayout lianxikefu;
    private LinearLayout shimingrenzheng;
    private LinearLayout zhuanjiarenzheng;
    private LinearLayout gerenxinxi;
    private LinearLayout yonghuxieyi;
    private LinearLayout yinsixieyi;
    private Button logoutButton;
    private LinearLayout CheckUpdate;
    private LinearLayout yinsishezhi;
    private LinearLayout denglumima;
    private LinearLayout tixianmima;
    private LinearLayout dizhiguanli;
    private LinearLayout guanyuwomen;
    private LinearLayout yijianfankui;
    private LinearLayout zhuxiaofuwu;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shezhi);
        settingBack=findViewById(R.id.shezhi_fanhui);
        lianxikefu=findViewById(R.id.lianxikefu);
        shimingrenzheng = findViewById(R.id.shimingrenzheng);
        zhuanjiarenzheng = findViewById(R.id.zhuanjiarenzheng);
        gerenxinxi = findViewById(R.id.gerenxinxi);
        yonghuxieyi=findViewById(R.id.yonghuxieyi);
        yinsixieyi=findViewById(R.id.yinsixieyi);
        CheckUpdate = findViewById(R.id.CheckUpdate);
        logoutButton = findViewById(R.id.btn_logout);
        yinsishezhi = findViewById(R.id.yinsishezhi);
        denglumima = findViewById(R.id.denglumima);
        tixianmima = findViewById(R.id.tixianmima);
        dizhiguanli = findViewById(R.id.dizhiguanli);
        guanyuwomen=findViewById(R.id.guanyuwomen);
        yijianfankui=findViewById(R.id.yijiandfankui);
        zhuxiaofuwu = findViewById(R.id.zhuxiaofuwu);

        settingBack.setOnClickListener(this);
        lianxikefu.setOnClickListener(this);
        shimingrenzheng.setOnClickListener(this);
        zhuanjiarenzheng.setOnClickListener(this);
        gerenxinxi.setOnClickListener(this);
        yonghuxieyi.setOnClickListener(this);
        yinsixieyi.setOnClickListener(this);
        CheckUpdate.setOnClickListener(this);
        logoutButton.setOnClickListener(this);
        yinsishezhi.setOnClickListener(this);
        denglumima.setOnClickListener(this);
        tixianmima.setOnClickListener(this);
        dizhiguanli.setOnClickListener(this);
        guanyuwomen.setOnClickListener(this);
        yijianfankui.setOnClickListener(this);
        zhuxiaofuwu.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.shezhi_fanhui){
            finish();
        } else if (id == R.id.gerenxinxi) {
            Intent intent = new Intent(shezhiActivity.this, GeRenZhongXinActivity.class);
            startActivity(intent);
        }else if (id == R.id.shimingrenzheng) {
            Intent intent = new Intent(shezhiActivity.this, ShiMingRenZhengActivity.class);
            startActivity(intent);
        }else if (id == R.id.zhuanjiarenzheng) {
            showRealNameAuthRequiredDialog();
        }else if (id == R.id.dizhiguanli) {
            Intent intent = new Intent(shezhiActivity.this, DizhiguanliActivity.class);
            startActivity(intent);
        }else if (id == R.id.yinsishezhi) {
            Intent intent = new Intent(shezhiActivity.this, yinsishezhiActivity.class);
            startActivity(intent);
        }else if (id == R.id.denglumima) {
            Intent intent = new Intent(shezhiActivity.this, XiugaimimaActivity.class);
            startActivity(intent);
        }else if (id == R.id.tixianmima) {
            Intent intent = new Intent(shezhiActivity.this, tixianmimaActivity.class);
            startActivity(intent);
        }else if (id == R.id.lianxikefu) {
                showCallDialog();
        }else if (id == R.id.yinsixieyi) {
            Intent intent = new Intent(shezhiActivity.this, YinsixieyiActivity.class);
            startActivity(intent);
        } else if (id == R.id.guanyuwomen) {
        Intent intent = new Intent(shezhiActivity.this, GuanyuwomenActivity.class);
        startActivity(intent);
        } else if (id == R.id.yijiandfankui) {
        Intent intent = new Intent(shezhiActivity.this, YijianfankuiActivity.class);
        startActivity(intent);
        }else if (id == R.id.yonghuxieyi) {
            Intent intent = new Intent(shezhiActivity.this, YonghuxieyiActivity.class);
            startActivity(intent);
        }else if (id == R.id.CheckUpdate) {
            showCheckUpdateDialog();
        }else if (id == R.id.zhuxiaofuwu) {
            Intent intent = new Intent(shezhiActivity.this, ZhuXiaoFuWuActivity.class);
            startActivity(intent);
        }else if (id == R.id.btn_logout) {
            // 清除用户登录信息
            clearUserId();
            // 跳转到登录页面
            Intent intent = new Intent(shezhiActivity.this, LoginActivity.class);
            // 清除任务栈，确保用户无法通过返回键回到之前的页面
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
            finish();
        }
    }

    private void showCallDialog() {
        new AlertDialog.Builder(this)
                .setTitle("温馨提示")
                .setMessage("您确定要拨打客服电话：0000-0000000")
                .setPositiveButton("确定", (dialog, which) -> {
                    Toast.makeText(this, "正在拨打电话...", Toast.LENGTH_SHORT).show();
                })
                .setNegativeButton("取消", null)
                .show();
    }
    private void showRealNameAuthRequiredDialog() {
        new AlertDialog.Builder(this)
                .setTitle("提示")
                .setMessage("店铺认证前，需要先通过实名认证~")
                .setNegativeButton("取消", null)
                .setPositiveButton("去认证", (dialog, which) -> {
            startActivity(new Intent(this, ShiMingRenZhengActivity.class));
        })
                .show();

    }
    private void showCheckUpdateDialog() {
        new AlertDialog.Builder(this)
                .setTitle("版本信息")
                .setMessage("当前已是最新版本!\n版本号:4.6.5_148")
                .setNegativeButton("确定", null)
                .show();

    }
    private void clearUserId() {
        // 清除保存的用户ID
        getSharedPreferences("user_info", MODE_PRIVATE).edit().remove("user_id").apply();
    }
}
